home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / sharewar / slunec / app / httrack.exe / {app} / src_win / WinHTTrack / InfoUrl.cpp < prev    next >
C/C++ Source or Header  |  2001-09-13  |  8KB  |  284 lines

  1. // InfoUrl.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Shell.h"
  6. #include "InfoUrl.h"
  7.  
  8. /* Externe C */
  9. extern "C" {
  10.   #include "htscore.h"
  11. }
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. extern HICON httrack_icon;
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CInfoUrl dialog
  23.  
  24.  
  25. CInfoUrl::CInfoUrl(CWnd* pParent /*=NULL*/)
  26.     : CDialog(CInfoUrl::IDD, pParent)
  27. {
  28.     //{{AFX_DATA_INIT(CInfoUrl)
  29.         // NOTE: the ClassWizard will add member initialization here
  30.     //}}AFX_DATA_INIT
  31. }
  32.  
  33.  
  34. void CInfoUrl::DoDataExchange(CDataExchange* pDX)
  35. {
  36.     CDialog::DoDataExchange(pDX);
  37.     //{{AFX_DATA_MAP(CInfoUrl)
  38.     DDX_Control(pDX, IDC_backlist, m_ctl_backlist);
  39.     DDX_Control(pDX, IDC_slider, m_slider);
  40.     //}}AFX_DATA_MAP
  41. }
  42.  
  43.  
  44. BEGIN_MESSAGE_MAP(CInfoUrl, CDialog)
  45.     //{{AFX_MSG_MAP(CInfoUrl)
  46.     ON_WM_TIMER()
  47.     ON_WM_CLOSE()
  48.     ON_BN_CLICKED(IDC_Freeze, OnFreeze)
  49.     ON_WM_CREATE()
  50.     ON_CBN_SELCHANGE(IDC_backlist, OnSelchangebacklist)
  51.     //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CInfoUrl message handlers
  56.  
  57. BOOL CInfoUrl::OnInitDialog() 
  58. {
  59.     CDialog::OnInitDialog();
  60.     
  61.   SetIcon(httrack_icon,false);
  62.   SetIcon(httrack_icon,true);  
  63.   SetForegroundWindow();   // yop en premier plan!
  64.  
  65.   // Patcher l'interface pour les Franτais ;-)
  66.   if (LANG_T(-1)) {    // Patcher en franτais
  67.     SetWindowText(LANG_X1);
  68.     SetDlgItemText(IDC_Freeze,LANG_X2);
  69.     SetDlgItemText(IDC_STATIC_moreinfos,LANG_X3);
  70.     SetDlgItemText(IDOK,LANG_CLOSE);
  71.   }
  72.  
  73.   StartTimer();
  74.     
  75.     return TRUE;  // return TRUE unless you set the focus to a control
  76.                   // EXCEPTION: OCX Property Pages should return FALSE
  77. }
  78.  
  79. void CInfoUrl::StartTimer() {
  80.   if (!timer) {
  81.     timer=SetTimer(WM_TIMER,100,NULL);
  82.   }
  83. }
  84. void CInfoUrl::StopTimer() {
  85.   if (timer) {
  86.     KillTimer(timer);
  87.     timer=0;
  88.     StatsBufferback=NULL;
  89.   }
  90. }
  91.  
  92. char* ToBool(int i) {
  93.   if (i)
  94.     return "yes";
  95.   else
  96.     return "no";
  97. }
  98.  
  99. char* ToStatuscode(int statuscode) {
  100.   if (statuscode<0) {
  101.     return "unknown status";
  102.   } else {
  103.     static char msg[1024];
  104.     msg[0]='\0';
  105.     infostatuscode(msg,statuscode);
  106.     return msg;
  107.   }
  108. }
  109.  
  110. char* ToStatus(int i) {
  111.   switch(i) {
  112.   case 0:
  113.     return "ready";
  114.     break;
  115.   case 1:
  116.     return "receiving";
  117.     break;
  118.   case 101:
  119.     return "searching dns";
  120.     break;
  121.   case 100:
  122.     return "waiting for connection";
  123.     break;
  124.   case 99:
  125.     return "receiving header";
  126.     break;
  127.   case 98:
  128.     return "receiving chunk header";
  129.     break;
  130.   case 1000:
  131.     return "ftp session";
  132.     break;
  133.   case -1:
  134.     return "empty";
  135.     break;
  136.   default:
  137.     return "unknown";
  138.     break;
  139.   }
  140. }
  141.  
  142. void CInfoUrl::OnTimer(UINT nIDEvent) 
  143. {
  144.   static char old_info[8192]="";
  145.   //
  146.   if (termine) {
  147.     EndDialog(IDOK);
  148.     return;
  149.   }
  150.   if (!StatsBufferback) return;
  151.   //
  152.   lien_back* back=(lien_back*) StatsBufferback;
  153.   //
  154.   if (m_ctl_backlist.GetDroppedState()==0) {
  155.     m_ctl_backlist.Clear();
  156.     m_ctl_backlist.ResetContent();
  157.     int i;
  158.     int back_max=StatsBufferback_max;
  159.     for(i=0;i<back_max;i++) {
  160.       if (termine) {
  161.         EndDialog(IDOK);
  162.         return;
  163.       }
  164.       if (back[i].status != -1) {
  165.         char st[HTS_URLMAXSIZE*4];
  166.         sprintf(st,"%02d: ",i);
  167.         strncat(st,back[i].url_adr,256);
  168.         strncat(st,back[i].url_fil,256);
  169.         m_ctl_backlist.AddString(st);
  170.       }
  171.     }
  172.   }
  173.   //
  174.   if (back) {
  175.     CInfoUrl box;
  176.     char info[8192]; info[0]='\0';
  177.     char total[256]; total[0]='\0';
  178.     char info100[256]; info100[0]='\0';
  179.     int offset=0;
  180.     if (back[id].status != -1) {        // utilisΘ
  181.       if (back[id].r.totalsize>0) {
  182.         sprintf(total,"%d",back[id].r.totalsize);
  183.         offset=(int) ((LONGLONG) ((LONGLONG) back[id].r.size*(LONGLONG) 100)/((LONGLONG) back[id].r.totalsize));
  184.         sprintf(info100,"(%d%%)",offset);
  185.       } else {
  186.         sprintf(total,"unknown");
  187.         sprintf(info100,"");
  188.       }
  189.       sprintf(info,"File: %s\r\nTotal length: %s\r\nBytes downloaded: %d %s\r\nCurrent state: %s",back[id].url_sav,total,back[id].r.size,info100,ToStatus(back[id].status));
  190.     }
  191.     //
  192.     if (strcmp(old_info,info)) {
  193.       char moreinfo[8192]; moreinfo[0]='\0';
  194.       lien_back* backitem=&back[id];
  195.       if (lien_back) {
  196.         if (back[id].status != -1) {        // utilisΘ
  197.           sprintf(moreinfo+strlen(moreinfo),"Host: %s\r\n",backitem->url_adr);
  198.           sprintf(moreinfo+strlen(moreinfo),"File: %s\r\n",backitem->url_fil);
  199.           sprintf(moreinfo+strlen(moreinfo),"Name: %s\r\n",backitem->url_sav);
  200.           if (backitem->location_buffer)
  201.             if (backitem->location_buffer[0])
  202.               sprintf(moreinfo+strlen(moreinfo),"MoveToLocation: %s\r\n",backitem->location_buffer);
  203.             //
  204.             sprintf(moreinfo+strlen(moreinfo),"ContentType: %s\r\n",backitem->r.contenttype);
  205.             //
  206.             sprintf(moreinfo+strlen(moreinfo),"StatusCode: %d (%s)\r\n",backitem->r.statuscode,ToStatuscode(backitem->r.statuscode));
  207.             sprintf(moreinfo+strlen(moreinfo),"InternalStatus: %d (%s)\r\n",backitem->status,ToStatus(backitem->status));
  208.             if (backitem->r.msg[0])
  209.               sprintf(moreinfo+strlen(moreinfo),"StatusMessage: %s\r\n",backitem->r.msg);
  210.             //
  211.             sprintf(moreinfo+strlen(moreinfo),"HTTP/1.1: %s\r\n",ToBool(backitem->r.req.http11));
  212.             sprintf(moreinfo+strlen(moreinfo),"ChunkMode: %s\r\n",ToBool(backitem->r.is_chunk));
  213.             if (backitem->is_chunk)
  214.               sprintf(moreinfo+strlen(moreinfo),"CurrentChunkSize: %s\r\n",backitem->chunk_size);
  215.             //
  216.             sprintf(moreinfo+strlen(moreinfo),"TestMode: %s\r\n",ToBool(backitem->testmode));
  217.             sprintf(moreinfo+strlen(moreinfo),"HeadRequest: %s\r\n",ToBool(backitem->head_request));
  218.             sprintf(moreinfo+strlen(moreinfo),"NotModified: %s\r\n",ToBool(backitem->r.notmodified));
  219.             //
  220.             sprintf(moreinfo+strlen(moreinfo),"WriteToDisk: %s\r\n",ToBool(backitem->r.is_write));
  221.             sprintf(moreinfo+strlen(moreinfo),"LocalFile: %s\r\n",ToBool(backitem->r.is_file));
  222.             //
  223.             sprintf(moreinfo+strlen(moreinfo),"Size: %d\r\n",backitem->r.size);
  224.             sprintf(moreinfo+strlen(moreinfo),"TotalSize: %d\r\n",backitem->r.totalsize);
  225.         } else
  226.           strcpy(moreinfo,"Transfer complete in this buffer, waiting for next file");
  227.       }
  228.       //
  229.       SetDlgItemText(IDC_InfoUrl,info);
  230.       SetDlgItemText(IDC_Info100,info100);
  231.       SetDlgItemText(IDC_MoreInfoUrl,moreinfo);
  232.       //
  233.       m_slider.SetRange(0,100);
  234.       m_slider.SetPos(offset);
  235.       m_slider.RedrawWindow();
  236.       //
  237.       strcpy(old_info,info);
  238.     }
  239.   }
  240.   //
  241.   CDialog::OnTimer(nIDEvent);
  242. }
  243.  
  244. void CInfoUrl::OnClose() 
  245. {
  246.   StopTimer();
  247.     CDialog::OnClose();
  248. }
  249.  
  250. void CInfoUrl::OnFreeze() 
  251. {
  252.   if (this->IsDlgButtonChecked(IDC_Freeze)) {
  253.     StopTimer();
  254.   } else {
  255.     StartTimer();
  256.   }
  257. }
  258.  
  259. int CInfoUrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  260. {
  261.     if (CDialog::OnCreate(lpCreateStruct) == -1)
  262.         return -1;
  263.     
  264.   timer=0;    
  265.  
  266.     return 0;
  267. }
  268.  
  269. void CInfoUrl::OnSelchangebacklist() 
  270. {
  271.   CString st;
  272.   int index=m_ctl_backlist.GetCurSel();
  273.   if (index!=CB_ERR) {
  274.     m_ctl_backlist.GetLBText(index,st);
  275.     int a=st.Find(':');
  276.     if (a>=0) {
  277.       char s[256]; s[0]='\0';
  278.       strncat(s,st,a);
  279.       sscanf(s,"%d",&id);
  280.       this->OnTimer(0);
  281.     }
  282.   }
  283. }
  284.